package cn.ultrawise.entity;

import cn.ultrawise.gameinterface.IEntity;
import cn.ultrawise.planeshootinggame.R;
import cn.ultrawise.view.GameView;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.View.OnTouchListener;

public class Bullet implements IEntity {
	int x;
	int y;
	int tableHeigh;
	int tableWidth;
	Bitmap bulletBitmap;
	private int type = 0;
	int moveSpeed;
	int dir;// 方向
	int bitmapId[] = new int[] { R.drawable.bullet, R.drawable.bullet2,
			R.drawable.bullet1, R.drawable.bullet_0 };
	GameView gameView = null;

	public Bullet() {
		super();
		initBitmap();
	}

	public Bullet(int x, int y, int tableHeigh, int tableWidth) {
		super();
		this.x = x;
		this.y = y;
		this.tableHeigh = tableHeigh;
		this.tableWidth = tableWidth;
		initBitmap();
	}

	public Bullet(int x, int y, int tableHeigh, int tableWdith, int type,
			int moveSpeed, int dir) {
		super();
		this.x = x;
		this.y = y;
		this.tableHeigh = tableHeigh;
		this.tableWidth = tableWdith;
		this.type = type;
		this.moveSpeed = moveSpeed;
		this.dir = dir;
		initBitmap();
	}

	@Override
	public void initBitmap() {
		// TODO Auto-generated method stub
		switch (type) {
		case 0:
			bulletBitmap = BitmapFactory.decodeResource(
					gameView.getResources(), bitmapId[0]);
			break;

		case 1:
			bulletBitmap = BitmapFactory.decodeResource(
					gameView.getResources(), bitmapId[1]);
			break;
		case 2:
			bulletBitmap = BitmapFactory.decodeResource(
					gameView.getResources(), bitmapId[2]);
			break;
		case 3:
			bulletBitmap = BitmapFactory.decodeResource(
					gameView.getResources(), bitmapId[3]);
			break;

		}
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public Bitmap getBulletBitmap() {
		return bulletBitmap;
	}

	public void setBulletBitmap(Bitmap bulletBitmap) {
		this.bulletBitmap = bulletBitmap;
	}

	@Override
	public void move() {
		// TODO Auto-generated method stub
		switch (dir) {
		case 0:
			if (y > 0) {
				y -= (moveSpeed + tableHeigh % 10);
			} else {

			}
			break;

		case 1:
			if (y < tableHeigh) {
				y += (moveSpeed + tableHeigh % 10);
			} else {

			}
			break;
		}
	}

	@Override
	public void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		canvas.drawBitmap(bulletBitmap, x, y, null);
	}

}
